<legend><<$lng.businesslead>></legend>
<<if ($displayBusinessLeadProfile)>>
<input type="hidden" name="extrabusinesslead" value="1">
<</if>>
<div>
<table><tr><td>
<div style="border:1px solid rgb(64,64,64);width:700px">
<table width="700px" style="<<if $smarty.section.bl.iterator == 0>>display:block;<<else>>display:none;<</if>>" class="formtable searchpanel">
<<if ($displayBusinessLeadProfile)>>
    <tr>
        <td colspan=2><label><<$lng.leadtype>></label>
        <input onclick="buysellChanged('1');" class="checkbox" <<if ($businessleads[bl].buysell='1')>> checked="checked" <</if>> type="radio" name="buysell" value="1"><<$lng.buyinglead>>
        <input onclick="buysellChanged('2');" class="checkbox" <<if ($businessleads[bl].buysell='2')>> checked="checked" <</if>> type="radio" name="buysell" value="2"><<$lng.sellinglead>>
        </td>
    </tr>
<</if>>
    <tr>
        <td colspan=2><label><<$lng.bl_productname>></label><Br><<inputtext value="" id="productname" onchange="productnameChanged()" name="productname">></td>
    </tr>
    <tr>
        <td colspan=2><<inputtextarea title="<<$lng.bl_description>>" name="description" class="width500" onblur="descriptionChanged()" value="">></td>
    </tr>
    <tr>
        <td colspan=2><label><<$lng.bl_hs4>></label><br>
        <<hsinput value="<<$businessleads[bl].hs4>>" id="businesslead_hs4" name="hs4">>
        <img id="businesslead_hs4_down" src="site/resources/img/icons/down.png" height=27 style="position:relative;top:8px;left:-20px;">
<!--        <input readonly="readonly" value="<<$businessleads[bl].hs4>>" hscode="<<$businessleads[bl].hs4>>" name="hs4" id="code_hs4" class="hsdropdown"> -->
        </td>
    </tr>
    <tr>
        <td valign="top"><<inputtext onchange="quantityChanged()" title="<<$lng.bl_quantity>>" name="quantity" class="width200" value="`$businessleads[bl].quantity`">></td>
        <td valign="top">
        <<inputchoice value="`$businessleads[bl].unit`" onchange="unitChanged()" itemlist="<<$lng.units>>" id="unit" name="unit" title="<<$lng.bl_unit>>" hint="Select quantity unit!">><br>
        </td>
    </tr>
    <tr>
        <td colspan=2><<inputtext onchange="coChanged()" value="`$businessleads[bl].country_origin`" title="<<$lng.bl_origin>>" name="country_origin" class="width500">></td>
    </tr>
    <tr>
        <td colspan=2><<inputtext onchange="cdChanged()" value="`$businessleads[bl].country_dest`" title="<<$lng.bl_dest>>" name="country_dest" class="width500">></td>
    </tr>
</table>

<p>
    <table style="display:none;" id="photo_payed">
    <tr><Td><<$lng.bl_uploadphoto>></td><td class="sponsor_payed"><<$lng.payed>></td></tr>
    </table>

    <table style="display:none;" id="photo_ordered">
    <tr><Td><<$lng.bl_uploadphoto>></td><td class="sponsor_payed"><<$lng.ordered>></td></tr>
    </table>

    <table style="display:none;">
    <tr><Td><<$lng.bl_uploadphoto>></td><td class="sponsor_waiting"><<$lng.waiting>></td></tr>
    </table>

    <table style="display:none;" class="formtable" id="photo_no">
        <tr>
            <td><input onclick="photoCheckboxClicked(this)" type="checkbox" class="checkbox row_allower sponsor" name="photo"><label for="photo"><<$lng.bl_uploadphoto>></label></td>
            <td><<fileuploader onchange="photoChanged" req_width=105 req_height=105 uploadfn="uploadBusinessLeadPhoto" title="<<$lng.bl_addphoto>>" name="photo_id">></td>
        </tr>
    </table>

</p>
</div>
</td><td valign="top">
<div>
<<$lng.bl_listtitle>><br>
<ul class="sidelist" id="businessleadlist">
<<section name="bl" loop="$businessleads">>
<li id="<<$smarty.section.bl.iteration-1>>"><<$businessleads[bl].productname>>
<<if ($businessleads[bl].renew == 1)>><b>!</b><</if>>
</li>
<</section>>
</ul>
<button onclick="addLead(); return false;"><<$lng.bl_addnew>></button>
</div>
</td></tr>
</table>

</div>

<p>
<b><<$lng.bl_bannersponsor>></b><Br>
<<if ($sponsor.spn_bl_rotator.status == "payed")>>
<table>
<tr><Td><<$lng.bl_bannerad>></td><td class="sponsor_payed"><<$lng.payed>></td></tr>
</table>
<<else if ($sponsor.spn_bl_rotator.status == "ordered")>>
<table>
<tr><Td><<$lng.bl_bannerad>></td><td class="sponsor_ordered"><<$lng.ordered>></td></tr>
</table>
<<else if ($sponsor.spn_bl_rotator.status == "waiting")>>
<table>
<tr><Td><<$lng.bl_bannerad>></td><td class="sponsor_waiting"><<$lng.waiting>></td></tr>
</table>
<<else>>
<table>
<tr><td><input class="checkbox row_allower sponsor" onclick="checkboxClicked()" type="checkbox" name="banner_ad"></td><Td><<$lng.bl_bannerad>></td><td> <<$lng.bannerfor>> <input type="text" name="banner_ad_month" class="multiplier month" value="<<$banner_ad_months>>" base="30000"> <<$lng.month>></td><td><span ref="banner_ad_month" class="sum"></span> HUF</td><td></td></tr>
</table>
<</if>>
</p><p>
<<fileuploader chgtitle="<<$lng.changebanner>>" value="<<$companyprofile.rotator_id>>" req_minwidth=710 req_minheight=90 req_width=732 req_height=120 uploadfn="uploadSponsorLogo" title="add banner" name="banner_id">>

</p>

<p>
<table>
<tr><td><input class="checkbox" type="checkbox" name="accept_tac"></td><td><<$lng.yestou>></td></tr>
<tr><td colspan="2"><<$lng.sendorder>></td></tr>
</table>
</p>
<p>
<<$lng.longterm>>
</p>
<table>
<tr><td>
<<$lng.total>>:
</td><td width="150px;">
<div style="background-color:#DEDEDE;width:auto;"><div style="display:inline;" id="amount"></div> HUF</div>
</td><td>
<div style="display:inline;" id="amount_eur"></div> EUR
</td><td>
<div style="display:inline;" id="amount_usd"></div> USD
</td><td>
<div style="padding-left:1cm;"><<$lng.totaldesc>></div>
</td><td>
<input type="text" name="discount" class="extra discount" style="width:130px;position:relative;top:8px;" onchange="recalculateAmount()">
</td></tr>
</table>
<input type="hidden" name="sponsoration_changed" value="0">


<<jqbutton id="renew" type="submit" title="<<$lng.bl_renew>>" style="width:180px;display:none;" onclick="renewBusinessLead('profile', 'Renewing business lead profile, please wait...', this); return false;">>

<<jqbutton type="submit" title="<<$lng.bl_save>>" style="width:180px;" onclick="submitBusinessLead('profile', 'Saving business lead profile, please wait...', this); return false;">>

<script>
function submitBusinessLead(formName, waitMsg, buttonItem) {
    businessleads[activeBusinessLead].hs4 = jQuery("input#businesslead_hs4").attr("datavalue").split(" - ")[0];
    businessleads[activeBusinessLead].unit = jQuery("input[type='hidden'][name='unit']").val();
    if (sponsorationChanged) { jQuery("input[name='sponsoration_changed']").val(1); } else { jQuery("input[name='sponsoration_changed']").val(0); }
    multiform_saveCurrentTab(jQuery("form[name='profile']"), 1, waitMsg, buttonItem, businessleads);
}

function renewBusinessLead(formName, waitMsg, buttonItem) {
    callService("companyprofile", "renewlead", {
        name : businessleads[activeBusinessLead].productname
    }, {
        success : function(result) {
            redirect("companyprofile", "success");
        }
    });
}

jQuery(".hsinput").hsInput({
    page : "companyprofile",
    hs2service : "geths2",
    hs4service : "geths4fromhs2",
    freetextservice : "gethsdata",
    emptyOnFocus : true,
    offsetLeft : -25,
    offsetTop : -5,
    defaulttext : "enter a product",
    selected : function(hsinputitem, value, code) {
        var id = jQuery(hsinputitem).attr("id");
        jQuery("#code_hs4").val(code);
        return false;
    }

/*
    page : "companyprofile",
    hs2service : "geths2",
    hs4service : "geths4fromhs2",
    freetextservice : "gethsdata",
    defaulttext : "enter a product",
    selected : function(hsinputitem, value, code) {
        var id = jQuery(hsinputitem).attr("id");
        jQuery("#code_hs4").val(code);
        return false;
    },
    change : function() {
    }
*/
});

function togglePhotoUploadButton(item) {
    if (item.checked) {
        jQuery("#photouploader").show("fade", {}, 300);
    } else {
        jQuery("#photouploader").hide("fade", {}, 300);
    }
}

jQuery("input[type='checkbox'].row_allower").allower({
    type : "row"
});

var freeaugust = {
    aftercalc : function(result, base, multiplier) {
        var d = new Date();
        var discount = d.getFullYear() == 2012 && d.getMonth() <= 6;
        if (discount) {
            if (multiplier == 1) { return "Free 2012"; }
            return (result - base) + " HUF";
        }
        return result + " HUF";
    }
};
jQuery("img#businesslead_hs4_down").click(function() {
    jQuery("input#businesslead_hs4").hsInput("openlist");
});

jQuery("input.multiplier").multiplier({});

jQuery("ul.sidelist li").click(function() {
    selectBusinesslead(this.id);
});


function addLead() {
    jQuery("table.searchpanel input").val("");
    jQuery("input[name='buysell'][value='1']").attr("checked", "checked");
    jQuery("table.searchpanel textarea").val("");
    jQuery("ul.sidelist").append(jQuery("<li>")
        .click(function() { selectBusinesslead(this.id); })
        .attr("id", businessleads.length)
        .html("Unnamed lead")
        .show("fade", {}, 300)
    );
    jQuery("input[type='checkbox'][name='photo']").attr("checked", false);
    fileuploader_setValue("photo_id", "");
    fileuploader_disable("photo_id");
    activeBusinessLead = businessleads.length;
    businessleads.push({});
}

var activeBusinessLead = 0;
var photoCount = 0;

var businessleads = [
<<section name="bl" loop="<<$businessleads>>">>
{businesslead_id : "<<$businessleads[bl].businesslead_id>>",
buysell : "<<$businessleads[bl].buysell>>",
productname : "<<$businessleads[bl].productname>>",
description : "<<$businessleads[bl].description>>",
hs4 : "<<$businessleads[bl].hs4>>",
country_origin : "<<$businessleads[bl].country_origin>>",
country_dest : "<<$businessleads[bl].country_dest>>",
quantity : "<<$businessleads[bl].quantity>>",
unit : "<<$businessleads[bl].unit>>",
photo_id : "<<$businessleads[bl].photo_id>>",
photo_sponsor_status : "<<$businessleads[bl].productphoto_sponsor_status>>",
renew : <<if ($businessleads[bl].renew == 1)>>true<<else>>false<</if>>
},
<</section>>
{}
];
businessleads.pop();

function selectBusinesslead(ndx, starter) {
    if (!starter) {
        businessleads[activeBusinessLead].hs4 = jQuery("input#businesslead_hs4").attr("datavalue").split(" - ")[0];
        businessleads[activeBusinessLead].unit = jQuery("input[type='hidden'][name='unit']").val();
    }
    activeBusinessLead = ndx;
    var row = businessleads[ndx];
    if (!row.buysell) {
        businessleads[activeBusinessLead].buysell = "2";
        row.buysell = "2";
    }
    if (businessleads[activeBusinessLead].renew) {
        jQuery("button[id='renew']").show();
    } else {
        jQuery("button[id='renew']").hide();
    }
    jQuery("input[name='productname']").val(row.productname);
    jQuery("input[name='buysell'][value='" + row.buysell + "']").attr("checked", "checked");
    jQuery("textarea[name='description']").val(row.description);
    jQuery("input#businesslead_hs4").attr("datavalue", row.hs4).val(row.hs4);
    jQuery("input[name='country_origin']").val(row.country_origin);
    jQuery("input[name='country_dest']").val(row.country_dest);
    jQuery("input[name='quantity']").val(row.quantity);
    jQuery("input[type='hidden'][name='unit']").val(row.unit);
    jQuery("input[type='text'][name='unit']").val(unit_items[row.unit-1]);
    fileuploader_setValue("photo_id", row.photo_id);
    if (row.photo_id != "" && row.photo_id != 0) {
        jQuery("input[type='checkbox'][name='photo']").attr("checked", true);
        fileuploader_enable("photo_id");
    } else {
        jQuery("input[type='checkbox'][name='photo']").attr("checked", false);
        fileuploader_disable("photo_id");
    }
    if (row.photo_sponsor_status == "payed") {
        jQuery("table#photo_payed").show();
        jQuery("table#photo_ordered").hide();
        jQuery("table#photo_no").hide();
    } else if (row.photo_sponsor_status == "ordered") {
        jQuery("table#photo_payed").hide();
        jQuery("table#photo_ordered").show();
        jQuery("table#photo_no").hide();
    } else {
        jQuery("table#photo_payed").hide();
        jQuery("table#photo_ordered").hide();
        jQuery("table#photo_no").show();
    }
}


selectBusinesslead(0, true);

function productnameChanged() {
    jQuery("ul.sidelist li[id='" + activeBusinessLead + "']").html(jQuery("input[name='productname']").val());
    businessleads[activeBusinessLead].productname = jQuery("input[name='productname']").val();
}

function descriptionChanged() {
    businessleads[activeBusinessLead].description = jQuery("textarea[name='description']").val();
}

function quantityChanged() {
    businessleads[activeBusinessLead].quantity = jQuery("input[name='quantity']").val();
}

function unitChanged() {
    businessleads[activeBusinessLead].unit = jQuery("input[type='hidden'][name='unit']").val();
}

function coChanged() {
    businessleads[activeBusinessLead].country_origin = jQuery("input[name='country_origin']").val();
}

function cdChanged() {
    businessleads[activeBusinessLead].country_dest = jQuery("input[name='country_dest']").val();
}

function photoChanged(fileId) {
    businessleads[activeBusinessLead].photo_id = fileId;
}

function buysellChanged(newValue) {
    businessleads[activeBusinessLead].buysell = newValue;
}

function photoCheckboxClicked(item) {
    if (item.checked) {
        photoCount++;
    } else {
        photoCount--;
    }
    recalculateAmount();
}

</script>
